'use strict';
/**
 * 发送消息提醒给微信关注用户
 */
const WechatApi = require('co-wechat-api');
const moment = require('moment');
class wechatApiService {
    // 发送模板消息
    constructor() {
        this.appId = 'wx833268732e68920c';
        this.appSecret = '92d5f8b18485998950486d25a41ca14c';
        this.url = 'https://www.baidu.com/';
        this.templateId = 'nQblm-9oBNSUJka_cqbH6vN4LkfaFhmPLWjP4Qce2EY';
        this.miniprogram = {
            appid: 'wx8a3e72751aa71401',
            // pagepath:"index?foo=bar"
        };
    }
    /**
     * 发送公众号消息
     * @param {*} opeinId 
     * @param {*} url 
     * @param {*} topColor 
     * @param {*} data 
     */

    async sendTemplate(opeinId, topColor, data) {
        const wxApi = new WechatApi(this.appId, this.appSecret);
        return await wxApi.sendTemplate(opeinId, this.templateId, this.miniprogram, topColor, this.getTemplateData(data));
    }
    /**
     * 微信宠物公众号，犬证审批进度消息提醒
     * @param data 
     */
    getTemplateData(data) {
        return {
            first: {
                value: data.first || '',
                color: "#173177"
            },
            keyword1: {
                value: data.subject || '',
                color: "#173177"
            },
            keyword2: {
                value: data.createTime || '', // moment(new Date(data.createTime)).format("YYYY年MM月DD日 HH:mm:ss"),
                color: '#173177',
            },
            keyword3: {
                value: data.content.length <= 20 ? data.content : data.content.substring(0, 20) + "...",
                color: "#173177"
            },
            remark: {
                value: data.remark || '',
                color: "#173177"
            }
        }
    }
}
module.exports = wechatApiService;